﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace nwrole.toolbox.sync.SourceConsole
{
    public static class SyncSettings
    {
        public static string SrcDbConnectionString
        {
            get { return ConfigurationManager.ConnectionStrings["SyncSourceDB"].ConnectionString; }
        }

        public static string SyncDbConnectionString
        {
            get { return ConfigurationManager.ConnectionStrings["SyncDB"].ConnectionString; }
        }
        
        public static TimeSpan SyncLockSpan
        {
            get { return new TimeSpan(0, 0, int.Parse(ConfigurationManager.AppSettings["SyncLockSeconds"])); }
        }

        public static ServiceConnectionInfo SyncSourceConnInfo
        {
            get
            {
                ServiceConnectionInfo connInfo = new ServiceConnectionInfo();

                ServiceConnectionInfo.ServiceConnectionType type;
                ServiceConnectionInfo.ServiceConnectionType.TryParse(ConfigurationManager.AppSettings["SyncSrcServiceConnType"], true, out type);
                connInfo.Type = type;

                connInfo.ServiceBusServiceNamespace = ConfigurationManager.AppSettings["SyncSrcServiceSBServiceNamespace"];
                connInfo.ServiceBusServicePath = ConfigurationManager.AppSettings["SyncSrcServiceSBServicePath"];
                connInfo.ServiceBusIssuerName = ConfigurationManager.AppSettings["SyncSrcServiceSBIssuerName"];
                connInfo.ServiceBusIssuerSecret = ConfigurationManager.AppSettings["SyncSrcServiceSBIssuerSecret"];

                connInfo.WebServiceBaseAddress = ConfigurationManager.AppSettings["SyncSrcServiceWSBaseAddress"];
                connInfo.WebServiceAddress = ConfigurationManager.AppSettings["SyncSrcServiceWSAddress"];

                return connInfo;
            }
        }

        public static ServiceConnectionInfo SyncDestinationConnInfo
        {
            get
            {
                ServiceConnectionInfo connInfo = new ServiceConnectionInfo();

                ServiceConnectionInfo.ServiceConnectionType type;
                ServiceConnectionInfo.ServiceConnectionType.TryParse(ConfigurationManager.AppSettings["SyncDestServiceConnType"], true, out type);
                connInfo.Type = type;

                connInfo.ServiceBusServiceNamespace = ConfigurationManager.AppSettings["SyncDestServiceSBServiceNamespace"];
                connInfo.ServiceBusServicePath = ConfigurationManager.AppSettings["SyncDestServiceSBServicePath"];
                connInfo.ServiceBusIssuerName = ConfigurationManager.AppSettings["SyncDestServiceSBIssuerName"];
                connInfo.ServiceBusIssuerSecret = ConfigurationManager.AppSettings["SyncDestServiceSBIssuerSecret"];

                connInfo.WebServiceBaseAddress = ConfigurationManager.AppSettings["SyncDestServiceWSBaseAddress"];
                connInfo.WebServiceAddress = ConfigurationManager.AppSettings["SyncDestServiceWSAddress"];

                return connInfo;
            }
        }
    }
}
